<template>
	<app-page>
		<wd-config-provider :theme="theme">
			<view class="container">
				<!-- 页面内容 -->
				<wd-cell-group>
					<wd-cell title="借贷本金" :value="dataValue.loanAmount" />
					<wd-cell title="总还款金额" :value="dataValue.all" />
					<wd-cell title="总利息" :value="dataValue.interest" />
				</wd-cell-group>

				<wd-table :data="dataList">
					<wd-table-col prop="date" label="起息日"></wd-table-col>
					<wd-table-col prop="endDate" label="结息日"></wd-table-col>
					<wd-table-col prop="rate" label="利率/年"></wd-table-col>
					<wd-table-col prop="days" label="天数"></wd-table-col>
					<wd-table-col prop="interest" label="利息"></wd-table-col>
					<wd-table-col prop="principal" label="还款本金"></wd-table-col>
					<wd-table-col prop="loanAmount" label="剩余本金"></wd-table-col>
				</wd-table>
			</view>
		</wd-config-provider>
	</app-page>
</template>

<script lang="ts">
	import { defineComponent, ref, getCurrentInstance, computed } from 'vue';

	import { onPageScroll, onLoad } from '@dcloudio/uni-app';



	export default defineComponent({
		name: '',
		components: {},
		setup(props, ctx) {
			// 日间light、夜间dark主题
			const theme = ref('light');
			const dataValue = ref({});
			onLoad(() => {
				let instance = getCurrentInstance();
				const eventChannel = instance.proxy.getOpenerEventChannel();
				let d = uni.getStorageSync('test-data') || "{}"
				dataValue.value = JSON.parse(d)
				console.log('222', dataValue.value)
				if (instance) {
					eventChannel.on('sendData', (data : any) => {
						console.log('111', data)
						dataValue.value = data;
						uni.setStorageSync('test-data', JSON.stringify(data))
					})
				}

				// 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据

			})
			const dataList = computed(() => {
				return dataValue.value.repaymentList ?? []
			})
			return {
				theme,
				dataValue,
				dataList
			};
		}
	});
</script>

<style lang="less" scoped>
	.container {}
</style>